package org.tang.springcloudvv.util;

import java.util.Calendar;
import java.util.Date;

/**
 * <p><em>Created on 2022/3/28 4:02 下午</em></p>
 *
 * @author fuzhongtang
 * @since 1.0.1
 */
public class DateUtil {
    public static Date addDays(Date date, int amount) {
        return add(date, Calendar.DAY_OF_MONTH, amount);
    }

    /*
     * calendarField取值比如：Calendar.HOUR
     */
    public static Date add(Date date, int calendarField, int amount) {
        if (date == null) {
            throw new IllegalArgumentException("The date must not be null");
        }
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(calendarField, amount);
        return c.getTime();
    }

}
